#!/usr/bin/env python
# -*- coding:utf-8 -*-

def gw_calc(input_val):
    range_list = (32,48,72,110,159,500)
    gw_err = 0
    if input_val < min(range_list):
        gw_err = 1
        return (gw_err,)
    for i,j in enumerate(range_list):
        if input_val >= j and input_val < range_list[i+1]:
            group_cat = i
            return (gw_err, group_cat)  # start from 0

def gh_calc(input_val, range_list, val_group):
    """
    用于计算输入数值对应的类型
    :param input_val: float,
    :param range_list: a tuple or list, ((e4,8),(8,15) )
    :param val_group: a tuple or list
    :return:
    """

    for i, ran in enumerate(range_list):
        low_b = ran[0]
        up_b = ran[1]
        if type(low_b) == str:
            if input_val >= float(low_b) and input_val <= up_b:
                # idx = i
                break
        else:
            if input_val > float(low_b) and input_val <= up_b:
                # idx = i
                break
        idx = i
    return val_group[i]

g1 = ("GS-1、（CSK-IA）", "Φ2×20-24dB", "5P 6×6 K2.5")
g2 = ("GS-1、（CSK-IA）", "Φ2×20-20dB", "5P 6×6 K2.5")
g3 = ("GS-1、（CSK-IA）", "Φ2×20-16dB", "2.5P 6×6 K2")
g4 = ("GS-2、（CSK-IA）", "Φ2×20-24dB", "5P 6×6 K2.5")
g5 = ("GS-2、（CSK-IA）", "Φ2×20-20dB", "5P 6×6 K2.5")
g6 = ("GS-2、（CSK-IA）", "Φ2×20-16dB", "2.5P 6×6 K2")
g7 = ("GS-3、（CSK-IA）", "Φ2×20-24dB", "5P 6×6 K2.5")
g8 = ("GS-3、（CSK-IA）", "Φ2×20-20dB", "5P 6×6 K2.5")
g9 = ("GS-3、（CSK-IA）", "Φ2×20-16dB", "2.5P 6×6 K2")
g10 = ("GS-4、（CSK-IA）", "Φ2×20-24dB", "5P 6×6 K2.5")
g11 = ("GS-4、（CSK-IA）", "Φ2×20-20dB", "5P 6×6 K2.5")
g12 = ("GS-4、（CSK-IA）", "Φ2×20-16dB", "2.5P 6×6 K2")
g13 = ("CSK-ⅠA、RB-C-1、（CSK-ⅡA）", "Φ2×40-18dB", "2.5（5）P 6×6 K2（2.5）或2.5（5）P 9×9 K2（2.5）")
g14 = ("CSK-ⅠA、RB-C-2、（CSK-ⅡA）", "Φ2×40-18dB", "2.5（5）P 6×6 K2（2.5）或2.5（5）P 9×9 K2（2.5）")
g15 = ("CSK-ⅠA、RB-C-3、（CSK-ⅡA）", "Φ2×40-18dB", "2.5（5）P 6×6 K2（2.5）或2.5（5）P 9×9 K2（2.5）")
g16 = ("CSK-ⅠA、RB-C-4、（CSK-ⅡA）", "Φ2×40-18dB", "2.5（5）P 6×6 K2（2.5）或2.5（5）P 9×9 K2（2.5）")
g17 = ("CSK-ⅠA、RB-C-5、（CSK-ⅡA）", "Φ2×40-18dB", "2.5（5）P 6×6 K2（2.5）或2.5（5）P 9×9 K2（2.5）")
g18 = ("CSK-ⅠA、RB-C-5、（CSK-ⅡA）", "Φ2×60-14dB", "2.5P 6×6 K1、K2或2.5 P 9×9 K1、K2（须两种K值探头）")
g19 = ("CSK-ⅠA、CSK-ⅡA", "Φ2×40-18dB", "2.5（5）P 9×9 K2（2.5）")
g20 = ("CSK-ⅠA、CSK-ⅡA", "Φ2×60-14dB", "2.5 P 9×9 K1、K2（须两种K值探头）")

conse = []
gw = 158.8
gh = 9.2
group_cat = gw_calc(gw)
print(group_cat)
if group_cat[0] == 0:
    group_map = ((g1,g2,g3),(g4,g5,g6),(g7,g8,g9),(g10,g11,g12),(g13,g14,g15,g16,g17,g18),(g19,g19,g20))

    b = gh_calc(gh ,(("4",8),(8,15),(15,float('inf'))),group_map[group_cat[1]])
    print(b)